﻿using System;
using Slf.Formatters;


namespace Slf.Samples.CustomFactorySettings
{
  /// <summary>
  /// A console logger that can be preconfigured with
  /// custom foreground / background colors.
  /// </summary>
  public class ColoredConsoleLogger : ConsoleLogger
  {
    public ConsoleColor? Foreground { get; set; }

    public ConsoleColor? Background { get; set; }


    public ColoredConsoleLogger(string name) : base(name)
    {
      //output everything on one line
      Formatter = SingleLineFormatter.Instance;
    }


    public override void Log(LogItem item)
    {
      Console.ResetColor();

      //set colors
      if (Foreground.HasValue) Console.ForegroundColor = Foreground.Value;
      if (Background.HasValue) Console.BackgroundColor = Background.Value;

      base.Log(item);
      Console.ResetColor();
    }
  }
}